#pragma once
#include "Channel.h"
#include "EventLoop.h"
#include <string>
using namespace std;
#include "Dispatcher.h"
#include <sys/select.h>

class SelectDispatcher : public Dispatcher
{
public:
    SelectDispatcher(EventLoop *eventLoop);

    int add() override;
    // 移除 ,把一个节点从epoll树上删除
    int remove() override;
    // 修改把一个节点从epoll树上修改
    int modify() override;
    // 事件检测 ，检测epoll树上是否有事件发生
    int dispatch(int timeout = 2) override; // 单位秒
    ~SelectDispatcher();

private:
    void setFdSet();
    void clearFdSet();

private:
    fd_set m_readset;
    fd_set m_writeSet;
    const int m_maxSize = 1024;
};